//
//  SMHomeTopView.swift
//  SomePasti
//
//  Created by 李永彬 on 2025/10/8.
//

import SwiftUI

struct SMHomeTopView: View {
    let viewModel: SMHomeViewModel
    let isLoading: Bool
    
    var onTapClosure: ((SMHomeViewModel) -> Void)?
    
    var body: some View {
        ZStack {
            // 背景图片
            Image("home_top_content_bg") // 替换为你的图片名称
                .resizable()
                .scaledToFit()
                .edgesIgnoringSafeArea(.all) // 如果需要全屏背景
            
            // 内容
            Group {
                if isLoading {
                    // 加载中的占位视图
                    ProgressView()
                        .frame(height: 200)
                } else if let topReceiveer = viewModel.topReceiveer {
                    // 显示真实数据
                    VStack(alignment: .leading, spacing: 12) {
                        Text(topReceiveer.passerency ?? "")
                            .font(.title2)
                            .fontWeight(.bold)
                        
                        Text("金额: \(topReceiveer.auctproof ?? "")")
                            .font(.body)
                        
                        Text("期限: \(topReceiveer.billionuous ?? "")")
                            .font(.body)
                        
                        Text("利率: \(topReceiveer.dexter ?? "")")
                            .font(.body)
                            .foregroundColor(.red)
                        
                        Text(topReceiveer.menaciability ?? "")
                            .font(.caption)
                            .foregroundColor(.gray)
                    }
                    .frame(maxWidth: .infinity, alignment: .leading)
                    .padding()
                    .background(Color.clear) // 添加透明度让背景透出
                    .cornerRadius(12)
                    .shadow(radius: 2)
                } else {
                    // 空数据状态
                    Text("暂无数据")
                        .foregroundColor(.gray)
                        .frame(height: 200)
                }
            }
            .padding() // 为内容添加内边距
        }
        .onTapGesture {
            onTapClosure?(viewModel)
        }
    }
}

#Preview {
//    SMHomeTopView()
}
